package com.blog.service.impl;

import com.blog.dao.ArticleDao;
import com.blog.dao.impl.ArticleDaoImpl;
import com.blog.pojo.Article;
import com.blog.service.ArticleService;

import java.util.List;
import java.util.Map;

public class ArticleServiceImpl implements ArticleService {

    ArticleDao articleDao=new ArticleDaoImpl();

    /**
     * 点赞数加一
     * @param articleId
     * @return
     */
    @Override
    public int addArticleStar(String articleId) {
        int i = articleDao.addStar(articleId);
        return i;
    }

    @Override
    public List<Article> getAllArticles() {
        return articleDao.getAllArticles();
    }

    @Override
    public List<Article> getTop10Articles() {
        List<Article> top10Articles = articleDao.getTop10Articles();
        for (Article article : top10Articles) {
            String content = article.getContent();
            if(content!=null&&content.length()>=200){
                content=content.substring(0,200)+".......";
            }
            article.setContent(content);
        }
        return top10Articles;
    }

    @Override
    public Map<String, Integer> getArticleSortAndCount() {
        return articleDao.getArticleSortAndCount();
    }

    @Override
    public List<Article> getTop10VisitArticles() {
        return articleDao.getTop10VisitArticles();
    }

    @Override
    public List<Article> getArticlesBySort(String sort) {
        return articleDao.getArticlesBySort(sort);
    }

    @Override
    public List<Article> getArticlesByTagName(String tagName) {
        return articleDao.getArticlesByTagName(tagName);
    }

    @Override
    public List<String> getArticlesYears() {
        return articleDao.getArticlesYears();
    }

    @Override
    public List<Article> getArticlesByYears(String year) {
        return articleDao.getArticlesByYears(year);
    }

    @Override
    public Article getById(String id) {
        return articleDao.getById(id);
    }

    @Override
    public Article getPreArticle(Integer id) {
        return articleDao.getPreArticle(id);
    }

    @Override
    public Article getNextArticle(Integer id) {
        return articleDao.getNextArticle(id);
    }

    @Override
    public int updateVisitCount(String id) {
        return articleDao.updateVisitCount(id);
    }

    @Override
    public int add(Article article) {
        return articleDao.add(article);
    }

    @Override
    public Article getLastedArticle() {
        return articleDao.getLastedArticle();
    }

    @Override
    public int deleteById(String articleId) {
        return articleDao.deleteById(articleId);
    }

    @Override
    public int deleteSort(String sortName) {
        return articleDao.deleteSort(sortName);
    }

    //依据文章名查找文章tag
    @Override
    public Article getArticlesById(String id) {
        return articleDao.getById(id);
    }

    @Override
    public int updateCommentCount(String mark,String id) {
        return articleDao.updateCommentCount(mark,id);
    }

    @Override
    public int edit(Article article) {
        return articleDao.edit(article);
    }

    @Override
    public int editSort(String sortName, String newSort) {
        return articleDao.editSort(sortName,newSort);
    }
}
